<template>
  <div>
    <!-- 使用挂载的宏 -->
    <button @click="runGetSessionStorage('1')">调用test</button>
	<button @click="runGetSessionStorage('2')">调用test</button>
	<button @click="runGetSessionStorage('3')">调用test</button>
	<button @click="getSe(1)">调用getSe</button>
	<input type="text" v-model="userId" placeholder="手机号码">
	<input type="password" v-model="password" placeholder="密码">
	<button @click="login()">调用login</button>
  </div>
</template>

<script>
	import { ref, getCurrentInstance } from 'vue';
export default {
	setup(){
		const currentInstance = getCurrentInstance();
		const userId = ref('');
		const password = ref('');
		const runGetSessionStorage = (keyStr) => {
		  currentInstance.appContext.config.globalProperties.$test(keyStr); // 调用getSessionStorage宏
		}
		const getSe = (orderTypeId) => {
			currentInstance.appContext.config.globalProperties.$axios.post(
					'BusinessController/listBusinessByOrderTypeId', currentInstance.appContext.config
					.globalProperties.$qs.stringify({
						orderTypeId: orderTypeId
					}))
				.then(response => {

					console.log(response.data);
					
				})
				.catch(error => {
					console.error(error);
				});
		}
		const login = () => {
			// currentInstance.appContext.config.globalProperties.$axios.post('UserController/getUserByIdByPass', currentInstance.appContext.config.globalProperties.$qs.stringify({
			// 	userId: userId,
			// 	password: password
			// })).then(response => {
			// 	let user = response.data;
			// 	if (user == null) {
			// 		alert('用户名或密码不正确！');
			// 	} else {
			// 		console.log(user);
			// 	}
			// }).catch(error => {
			// 	console.error(error);
			// });
			console.log(userId);
			console.log(password);
			currentInstance.appContext.config.globalProperties.$axios.post(
					'UserController/getUserByIdByPass', currentInstance.appContext.config
					.globalProperties.$qs.stringify({
						userId: userId.value,
						password: password.value
					}))
				.then(response => {
					console.log(response.data);
					let user = response.data;
					if(user == null){
						alert("用户名或密码不正确！");
					}
				})
				.catch(error => {
					console.error(error);
				});
		}
		return{
			runGetSessionStorage,
			getSe,
			login,
			userId,
			password
		}
	}
 //  methods: {
 //    runGetSessionStorage(keyStr) {
 //      this.$test(keyStr); // 调用getSessionStorage宏
 //    },
	// getSe(orderTypeId){
	// 	this.$axios.post('BusinessController/listBusinessByOrderTypeId', {
	// 	  orderTypeId: orderTypeId
	// 	})
	// 	.then(response => {
			
	// 	})
	// 	.catch(error => {
	// 	  console.error(error);
	// 	});
	// }
 //  }
};
</script>